package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.example.config.RocketMQConfigProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/rpc")
public class RpcController {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Autowired
    private RocketMQConfigProperties prop;

    @RequestMapping("/send")
    public String send() {
        // rpc发送
        String responseMessage = rocketMQTemplate.sendAndReceive(prop.getTopic().get("rpc"), "我是rpc message", String.class);
        log.info("rpc Listener发送结果："+responseMessage);
        return "ok";
    }
}
